<template>
  <div class="addBlog">
    <div class="addMain">
      <label for="title">
        <p>标题</p>
        <input
          type="text"
          v-model="addBlog.title"
          name="title"
          id="title"
          placeholder="标题..."
        />
      </label>
      <label for="author">
        <p>作者</p>
        <input
          v-model="addBlog.author"
          type="text"
          name="author"
          id="author"
          placeholder="作者信息..."
        />
      </label>
      <label for="classify">
        <p>分类</p>
        <select v-model="addBlog.classify" name="classify" id="classify">
          <option value="javascript">javascript</option>
        </select>
      </label>
      <QuillEditor @content="contentt" />
      <p class="time">发表时间:{{ this.addBlog.time }}</p>
      <input class="btnSub" type="submit" value="发表博客" @click="onSubmit" />
    </div>
  </div>
</template>

<script>
import time from "../assets/js/time";
import QuillEditor from "./QuillEditor";
export default {
  components: {
    QuillEditor,
  },
  data() {
    return {
      addBlog: {
        title: "",
        author: "",
        classify: "",
        content: "",
        time: time.newDate(),
      },
    };
  },
  methods: {
    contentt(val) {
      this.addBlog.content = val;
    },
    onSubmit() {
      this.$http.post("/blog", this.addBlog).then(
        (res) => {
          console.log(res);
          alert("发表成功！");
          this.$router.push("/blog/articleList");
        },
        (err) => {
          console.log(err);
        }
      );
    },
  },
};
</script>

<style lang="less" scope>
.addBlog {
  max-width: 1000px;
  height: 100%;
  margin: 0 auto;
  .addMain {
    padding-top: 20px;
    label {
      margin-bottom: 20px;
      color: white;
      display: block;
      input {
        width: 30%;
        height: 40px;
        margin-top: 10px;
        background-color: transparent;
        outline: none;
        border: 1px solid white;
        border-radius: 3px;
        cursor: text;
        color: white;
        input[type="text"]::placeholder {
          opacity: 1;
        }
        input[type="text"]:focus::placeholder {
          opacity: 0;
        }
      }
      select {
        margin-top: 10px;
        display: block;
        width: 120px;
        height: 35px;
        text-align: center;
        background-color: transparent;
        border: 1px solid white;
        border-radius: 3px;
        color: white;
        font-size: 1rem;
      }
    }
    .time {
      color: white;
    }
    .btnSub {
      width: 100px;
      height: 40px;
      margin: 10px auto;
      display: block;
      background-color: transparent;
      cursor: pointer;
      border: 1px solid white;
      font-size: 1rem;
      color: rgb(9, 9, 9);
      font-weight: 550;
      border-radius: 3px;
      transform: 0.5s;
    }
    .btnSub:hover {
      box-shadow: 0 0 5px white;
    }
    .btnSub:active {
      color: rgb(56, 141, 33);
    }
  }
}
</style>